package com.ar.logreader.tray;

import java.awt.Image;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
 
public class TrayIconBasic {
 
    public static void main(String[] args) {
    	try {
			UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
			SwingUtilities.invokeLater(new Runnable() {
				public void run() { createAndShowGUI(); }
			});
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
 
    protected static void createAndShowGUI(){
    	//Check the SystemTray support
    	try {
	        if (!SystemTray.isSupported()) {
	            System.out.println("SystemTray is not supported");
	            return;
	        }
	    	
	        final SystemTray tray = SystemTray.getSystemTray();
	        final TrayIcon trayIcon = new TrayIcon(createImage("../images/Aion.png", "tray icon"));
	        trayIcon.setImageAutoSize(Boolean.TRUE);
	        TrayMenu trayMenu = new TrayMenu(tray);
	        trayIcon.setPopupMenu(trayMenu.getTrayMenu());
			tray.add(trayIcon);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("Cannot add trayicon");
		}
	}
    
    protected static Image createImage(String path, String description) {
        URL imageURL = TrayIconBasic.class.getResource(path);
        return imageURL == null ? null : (new ImageIcon(imageURL, description)).getImage();
    }
}